const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');

module.exports = {
	//entry: './src/index.js',   // 单入口
	entry: {
		app: './src/index.js',
		//print: './src/print.js'
	},
	output: {
		//filename: 'bundle.js',    // 单入口
		filename: '[name].bundle.js', // 多入口[name]
		path: path.resolve(__dirname, 'dist')
	},
	module: {
		rules: [{ // 加载 css 文件    ->  style-loader ,  css-loader
				test: /\.css$/,
				use: [
					'style-loader',
					'css-loader'
				]
			}, { // 加载图片文件  -> file-loader
				test: /\.(png|svg|jpg|gif)$/,
				use: [
					'file-loader', {
						loader: 'image-webpack-loader', // 图片压缩
						options: {
							bypassOnDebug: true,
						}
					}
				]
			},
			{
				test: /\.(woff|woff2|eot|ttf|tof)$/, // 加载字体库 -> file-loader
				use: [
					'file-loader'
				]
			}
		]
	},
	devtool: 'inline-source-map', // 有错误  源映射
	devServer: {
		contentBase: './dist',
		hot: true
	},
	plugins: [
		new HtmlWebpackPlugin({ //自动生成html 并且应用 js
			title: 'output zy'
		}),
		new CleanWebpackPlugin(['dist']), // 在每次构建前清理 /dist 文件夹
		new webpack.HotModuleReplacementPlugin()

	]
}